import GameCfgData from "../../lib/GameCfgData";
import Utils from "../../lib/Utils";

export default class ItemBaseData{
    public static WIDTH:number=60;
    public static ITEM_FLAG:string="ITEM_FLAG";
    public static TXT_FLAG:string="TXT_FLAG";
    public id:number;
    public colorIndex:number=0;
    public index:number=0;
    public name:string;
    public type:number=0;
    public icon:string;
    public price:number;
    public row:number;
    public col:number;
    public unlockLevel:number=0;
    public size:number=1;
    public area:number;
    public num:number=1;
    constructor(_id:number=0){
        if(_id>0)this.setDataById(_id);
    }

    public parse(_value:string){

    }

    public copy(_cfg,_id:number=null){
        Utils.copyObjAtt(this,_cfg);
        if(_id){
            Utils.copyObjAtt(this,GameCfgData.getIns().getItem(_id));
        }
    }

    public setDataById(_id){
        if(_id)Utils.copyObjAtt(this,GameCfgData.getIns().getItem(_id));
    }

    public restSomeThings(){
        this.area=null;
    }

    public get isPao():boolean{
        return this.type==1;
    }

    public get isCanMove(){
        if(this.isPao || this.isDisposeConnectProp){
            return true;
        }
        return false;
    }

    /**水泡*/
    public get isBlister(){
        return this.id==1001;
    }

    public get isDiamand(){
        return this.type==3;
    }

    public get isColorDiamand(){
        return this.type==4;
    }

    public get isDiamandType(){
        return this.isDiamand || this.isColorDiamand;
    }

    public get is3RandomDispose(){
        return this.id==1009 || this.id==100001;
    }

    public get isBomb(){
        return this.id==1008;
    }

    public get isChangeToTouch(){
        return this.id==1012;
    }

    /**发射的泡泡碰到就消除*/
    public get isKe(){
        return this.id==1003;
    }

    public get isRowLine(){
        return this.id==1013;
    }
    
    public get isCanConnectDisposePao(){
        if(this.colorIndex && this.colorIndex>0)return true;
        return false;
    }

    public get isCanDispose(){
        if(this.isDiamand)return false;
        return true;
    }

    /**可以被炸毁的*/
    public get isCanBombDosposeSpItem(){
        if(this.id==1002)return true;
        return false;
    }
    
    /**碰到就消失并触发效果*/
    public get isSpPao(){
        if(this.is3RandomDispose || this.isBomb || this.isChangeToTouch || this.isKe || this.isRowLine)return true;
        return false;
    }
    
    public get isProp(){
        return false;
    }
    public get isDisposeConnectProp(){
        return this.id==100004;
    }

    public get isLineProp(){
        return this.id==100005;
    }

    public get isBombProp(){
        return this.id==100003;
    }

    public get isBigBombProp(){
        return this.id==100006;
    }

    public get isShowMoreProp(){
        return this.id==100002;
    }

    public setRC(_row:number,_col:number){
        this.row=_row;
        this.col=_col;
    }
    public  getAreaRCs(){
        if(!this.area)return null;
        let tarr = [];
        if(this.area==1)tarr=ItemBaseData.getDownPos(this.row,this.col);
        else if(this.area==2)tarr=ItemBaseData.getUpPos(this.row,this.col);
        else if(this.area==3)tarr=ItemBaseData.getDownPos2(this.row,this.col);
        else if(this.area==4)tarr=ItemBaseData.getUpPos2(this.row,this.col);
        else if(this.area==5)tarr=ItemBaseData.getBoudsRcs(this.row,this.col);
        return tarr;
    }

    /** 掉落下来时的积分*/
    public getDropScore(){
        let tscore = 100;
        if(this.isPao){
            //tscore=100;
            if(this.isDiamandType){
                tscore = 500;
                if (this.area > 3) tscore = 3000;
                else if (this.area) tscore = 2000;
            }
        } else if (this.id == 1002) tscore = 250;
        else if (this.isBlister) tscore = 150;
        else if (this.isBomb) tscore = 1000;
        return tscore;
    }
    
    public getStr(){
        return this.id+"_"+this.row+"_"+this.col;
    }
    
    public get flag(){
        let tflag="items";
        
        return tflag;
    }

    public get rcFlag(){
        return this.row+"_"+this.col;
    }

    public clone(){
        let tdata:ItemBaseData=new ItemBaseData();
        Utils.copyObjAtt(tdata,this);
        return tdata;
    }
    
    public static getBoudsRcs(_row:number,_col:number){
        let tarr=[];
        tarr.push({row:_row,col:_col-1});
        tarr.push({row:_row,col:_col+1});
        if(this.isSingleRow(_row)){
            tarr.push({row:_row-1,col:_col-1});
            tarr.push({row:_row-1,col:_col});
            tarr.push({row:_row+1,col:_col-1});
            tarr.push({row:_row+1,col:_col});
        }else{
            tarr.push({row:_row-1,col:_col+1});
            tarr.push({row:_row-1,col:_col});
            tarr.push({row:_row+1,col:_col+1});
            tarr.push({row:_row+1,col:_col});
        }
        return tarr;
    }

    public static getUpPos(_row:number,_col:number){
        let tarr=[];
        if(this.isSingleRow(_row)){
            tarr.push({row:_row-1,col:_col-1});
            tarr.push({row:_row-1,col:_col});
        }else{
            tarr.push({row:_row-1,col:_col+1});
            tarr.push({row:_row-1,col:_col});
        }
        return tarr;
    }

    public static getUpPos2(_row:number,_col:number){
        let tarr=[];
        if(this.isSingleRow(_row)){
            tarr.push({row:_row-1,col:_col-1});
            tarr.push({row:_row-1,col:_col});
        }else{
            tarr.push({row:_row-1,col:_col+1});
            tarr.push({row:_row-1,col:_col});
        }
        tarr.push({row:_row-2,col:_col});
        tarr.push({row:_row-2,col:_col-1});
        tarr.push({row:_row-2,col:_col+1});
        return tarr;
    }
    public static getDownPos(_row:number,_col:number){
        let tarr=[];
        if(this.isSingleRow(_row)){
            tarr.push({row:_row+1,col:_col-1});
            tarr.push({row:_row+1,col:_col});
        }else{
            tarr.push({row:_row+1,col:_col+1});
            tarr.push({row:_row+1,col:_col});
        }
        return tarr;
    }
    public static getDownPos2(_row:number,_col:number){
        let tarr=[];
        if(this.isSingleRow(_row)){
            tarr.push({row:_row+1,col:_col-1});
            tarr.push({row:_row+1,col:_col});
        }else{
            tarr.push({row:_row+1,col:_col+1});
            tarr.push({row:_row+1,col:_col});
        }
        tarr.push({row:_row+2,col:_col});
        tarr.push({row:_row+2,col:_col-1});
        tarr.push({row:_row+2,col:_col+1});
        return tarr;
    }
    
    /**是否是偶数*/
    public static isSingleRow(_row:number): boolean{
        return _row%2==0;
    }

    public static getPosByRC(_row:number,_col:number){
       let toffx = this.isSingleRow(_row)?0:this.WIDTH/2;
       let toff=this.WIDTH/2;
       return {x:toff+_col*this.WIDTH+toffx,y:toff+_row*this.WIDTH};
    }

    public static getRCByPos(_x:number,_y:number){
        let toff = ItemBaseData.WIDTH/2;
        let trow:number=Math.floor(_y/ItemBaseData.WIDTH);
        let tcol=ItemBaseData.isSingleRow(trow)?Math.floor(_x/ItemBaseData.WIDTH):Math.floor((_x-toff)/ItemBaseData.WIDTH);
        return {row:trow,col:tcol};
    }

   
   
    
}